﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using AjaxControlToolkit;
using CoolCode.Web.UI;

namespace CoolCode.Web.Ajax
{
    internal  class AjaxPageManager : ControlManager, IControlManager 
    {
        private ISetTextRule _setTextRule;
        public override  ISetTextRule SetTextRule
        {
            get
            {
                if (_setTextRule == null)
                    _setTextRule = new AjaxSetTextRule();
                return _setTextRule;
            }
            set { _setTextRule = value; }
        }

        public AjaxPageManager(IControl container, ISetTextRule setTextRule)
            : base(container, setTextRule  )
        {
        }

        public override void LoadJs( string jsFileName)
        {
             ToolkitScriptManager.RegisterClientScriptInclude(this.Page, this.Page.GetType(), jsFileName, jsFileName);
        }
    }

    internal class AjaxSetTextRule : DefaultSetTextRule, ISetTextRule
    {
        public override bool SimpleSetText(Control c, string text)
        {
            if (base.SimpleSetText(c, text))
                return true;
            else
            {
                if (c is ConfirmButtonExtender)
                {
                    ConfirmButtonExtender cc = (ConfirmButtonExtender)c;
                    cc.ConfirmText = text;
                }
                else
                {
                    return false;
                }
            }
            return true;
        }
    }

}
